var aqiUrl = 'https://free-api.heweather.com/v5/weather?city=CN101230201&key=34e00517398447ecad73ffdeb2fdb915';

var app = getApp();
function requestWeatherData(callback) {
  wx.request({
    url: aqiUrl,
    data: {},
    method: 'Get',
    success: function (res) {
      var result = parseWeatherData(res);
      callback(true, result);
    },
    fail: function (res) {
      callback(false);
    }
  });
}
function parseWeatherData(orign) {
  var weather = {};
  console.log(orign);
  var data = orign.data.HeWeather5[0];
  weather.city = data.basic.city;
  weather.now = data.now;
  weather.daily = data.daily_forecast;
  weather.aqi = data.aqi.city;
  weather.suggestion = data.suggestion;
  weather.alarms = data.alarms;
  console.log(weather);
  return (weather);
}
function loadWeatherData(callback) {
  requestWeatherData(callback);
}
module.exports = { loadWeatherData: loadWeatherData }